//
//  SWRetweetView.swift
//  SinaWeibo
//
//  Created by wszyxc on 16/7/23.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

import UIKit

class SWBottomView: UIView {
    
    private var retweetBtn:UIButton?
    private var commentBtn:UIButton?
    private var likeBtn:UIButton?
    
    var originalViewModel:SWOriginalViewModel?{
        
        
        didSet{
            
            retweetBtn?.setTitle(originalViewModel?.repostsCount, forState: .Normal)
            commentBtn?.setTitle(originalViewModel?.commentsCount, forState: .Normal)
            likeBtn?.setTitle(originalViewModel?.attitudesCount, forState: .Normal)
        }
        
    }
    


   override init(frame: CGRect) {
        super.init(frame: frame)
    
        setupUI()
    
        backgroundColor = UIColor.whiteColor()
    
    }

   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
    
    
    private func setupUI(){
        
        
        retweetBtn = addBtn("timeline_icon_retweet", title: "转化")
        commentBtn = addBtn("timeline_icon_comment", title: "评论")
        likeBtn = addBtn("timeline_icon_unlike", title: "赞")
        
        retweetBtn!.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.leading.equalTo(self)
            make.width.equalTo(commentBtn!)
        }
        
        commentBtn!.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetBtn!.snp_trailing)
            make.width.equalTo(likeBtn!)
            
        }
        likeBtn!.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(commentBtn!.snp_trailing)
            
        }
        
            
        }
    

    private func addBtn(imageName:String,title:String) -> UIButton{
        
        let btn = UIButton()
        
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(13)
        
        addSubview(btn)
        
        return btn
        
    }
    
    

}
